package com.shawn.spring.boot.mybatis.mapper;

import com.shawn.spring.boot.mybatis.entity.Role;
import com.shawn.spring.boot.mybatis.entity.RoleExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface RoleMapper {
  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  long countByExample(RoleExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int deleteByExample(RoleExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Delete({"delete from t_role", "where role_id = #{roleId,jdbcType=BIGINT}"})
  int deleteByPrimaryKey(Long roleId);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Insert({
    "insert into t_role (role_name, remark, ",
    "create_time, update_time, ",
    "is_deleted)",
    "values (#{roleName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, ",
    "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
    "#{isDeleted,jdbcType=TINYINT})"
  })
  @SelectKey(
      statement = "SELECT LAST_INSERT_ID()",
      keyProperty = "roleId",
      before = false,
      resultType = Long.class)
  int insert(Role record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int insertSelective(Role record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  List<Role> selectByExampleWithRowbounds(RoleExample example, RowBounds rowBounds);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  List<Role> selectByExample(RoleExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Select({
    "select",
    "role_id, role_name, remark, create_time, update_time, is_deleted",
    "from t_role",
    "where role_id = #{roleId,jdbcType=BIGINT}"
  })
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.RoleMapper.BaseResultMap")
  Role selectByPrimaryKey(Long roleId);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByExampleSelective(@Param("record") Role record, @Param("example") RoleExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByExample(@Param("record") Role record, @Param("example") RoleExample example);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  int updateByPrimaryKeySelective(Role record);

  /**
   * This method was generated by MyBatis Generator. This method corresponds to the database table
   * t_role
   *
   * @mbg.generated Sun Aug 30 18:19:25 CST 2020
   */
  @Update({
    "update t_role",
    "set role_name = #{roleName,jdbcType=VARCHAR},",
    "remark = #{remark,jdbcType=VARCHAR},",
    "create_time = #{createTime,jdbcType=TIMESTAMP},",
    "update_time = #{updateTime,jdbcType=TIMESTAMP},",
    "is_deleted = #{isDeleted,jdbcType=TINYINT}",
    "where role_id = #{roleId,jdbcType=BIGINT}"
  })
  int updateByPrimaryKey(Role record);

  @Insert("Insert into t_role_menu (role_id, menu_id) values (#{roleId}, #{menuId})")
  int insertRoleMenu(@Param("roleId") long roleId, @Param("menuId") long menuId);

  @Select(
      "select r.* from t_role r left join t_user_role ur on ur.role_id = r.role_id where ur.user_id = #{userId}")
  @ResultMap("com.shawn.spring.boot.mybatis.mapper.RoleMapper.BaseResultMap")
  List<Role> selectByUserId(@Param("userId") long userId);
}
